package cn.cq.admin.controller;

import cn.cq.admin.entity.dto.BatchDto;
import cn.cq.admin.entity.dto.BatchRemove;
import cn.cq.admin.entity.model.Batch;
import cn.cq.admin.entity.vo.BatchVo;
import cn.cq.admin.service.BatchService;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/batch")
public class BatchController {
    @Resource
    private BatchService batchService;

    @PostMapping("/doList")
    public SaResult doList(@RequestBody BatchDto batchDto) {
        return batchService.doList(batchDto);
    }

    @PostMapping("/doSave")
    public SaResult doSave(@RequestBody BatchDto batchDto) {
        batchService.doSave(batchDto);
        return SaResult.ok("新增成功");
    }
    @DeleteMapping("/doRemove")
    public SaResult doRemove(@RequestBody BatchRemove batchRemove) {
        batchService.doRemove(batchRemove.getIds());
        return SaResult.ok("删除成功");
    }
    @PutMapping("/doModify")
    public SaResult doModify(@RequestBody BatchDto batchDto) {
        batchService.doModify(batchDto);
        return SaResult.ok("修改成功");
    }
    @PutMapping("/doModifyStatus/{id}/{status}")
    public SaResult doModifyStatus(@PathVariable Long id,@PathVariable Integer status){
        batchService.doModifyStatus(id,status);
        return SaResult.ok("修改状态成功");
    }
    @GetMapping("/doListAll")
    public SaResult doListAll() {
        List<BatchVo> batchVos = batchService.doListAll();
        return SaResult.data(batchVos);
    }

}
